(function (vc, vm) {

    vc.extends({
        data: {
            editShopSmsSwitchInfo: {
                smsId: '',
                shopId: '',
                smsSwitch: '',

            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('editShopSmsSwitch', 'openEditShopSmsSwitchModal', function (_params) {
                $that.refreshEditShopSmsSwitchInfo();
                $('#editShopSmsSwitchModel').modal('show');
                vc.copyObject(_params, $that.editShopSmsSwitchInfo);
                $that.editShopSmsSwitchInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            editShopSmsSwitchValidate: function () {
                return vc.validate.validate({
                    editShopSmsSwitchInfo: $that.editShopSmsSwitchInfo
                }, {
                    'editShopSmsSwitchInfo.shopId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "店铺ID不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "店铺ID不能超过30"
                        },
                    ],
                    'editShopSmsSwitchInfo.smsId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "编号不能为空"
                        }
                    ],
                });
            },
            editShopSmsSwitch: function () {
                if (!$that.editShopSmsSwitchValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    '/shopSms.updateShopSmsSwitch',
                    JSON.stringify($that.editShopSmsSwitchInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editShopSmsSwitchModel').modal('hide');
                            vc.emit('shopConfigSms','listShopSms', {});
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);
                    });
            },
            refreshEditShopSmsSwitchInfo: function () {
                $that.editShopSmsSwitchInfo = {
                    smsId: '',
                    shopId: '',
                    smsSwitch: '',

                }
            }
        }
    });

})(window.vc, window.$that);
